package com.icode.core.model.house;

import com.icode.core.model.AbstractEntity;

import javax.persistence.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sunk
 * Date: 15-1-12
 * Time: 下午11:31
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "house_base")
public class HouseBase extends AbstractEntity {
    @Column
    private String title;
    @Column
    private String introduction;
    @Column
    private String information;
    @Column
    private String price;

    @Column(name = "house_base_area")
    @Enumerated(EnumType.STRING)
    private HouseBaseArea houseBaseArea;

    @Column(name = "product_type")
    @Enumerated(EnumType.STRING)
    private ProductType productType;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "house_base_id")
    private List<HouseBaseImage> houseBaseImages;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "house_base_id")
    private List<BuildingType> buildingTypes;
        /*
         It is considering whether to delete this domain and Relieve the relationship of object ?
         */
    //    @OneToMany(cascade = CascadeType.ALL)
//    @JoinColumn(name = "house_base_id")
//    private List<HouseBaseThemes> houseBaseThemes;

    private String themes;
    @Column(columnDefinition = "bit", name = "fine_theme")
    private boolean fineTheme;

    private int sort;

    public HouseBase() {
    }

    public HouseBase(String title, String introduction, String information, String price, ProductType productType, HouseBaseArea houseBaseArea, String themes, boolean fineTheme) {
        this.title = title;
        this.introduction = introduction;
        this.information = information;
        this.price = price;
        this.productType = productType;
        this.houseBaseArea = houseBaseArea;
        this.themes = themes;
        this.fineTheme = fineTheme;
    }

    public void initHouseBase(String title, String introduction, String information, String price, ProductType productType, HouseBaseArea houseBaseArea, String themes, boolean fineTheme) {
        this.title = title;
        this.introduction = introduction;
        this.information = information;
        this.price = price;
        this.productType = productType;
        this.houseBaseArea = houseBaseArea;
        this.themes = themes;
        this.fineTheme = fineTheme;
    }

//    public void initHouseBaseThemes(List<HouseBaseThemes> houseBaseThemes) {
//        this.houseBaseThemes = houseBaseThemes;
//    }

    public void initImages(List<HouseBaseImage> houseBaseImages) {
        this.houseBaseImages = houseBaseImages;
    }

    public String houseBaseThemesToString(List<HouseBaseThemes> houseBaseThemeses) {
        String result = "";
        for (HouseBaseThemes h : houseBaseThemeses) {
            result += h.houseBaseTheme().getLabel() + ",";
        }
        return result;
    }

    public String title() {
        return title;
    }

    public String introduction() {
        return introduction;
    }

    public HouseBaseArea houseBaseArea() {
        return houseBaseArea;
    }


    public String information() {
        return information;
    }

    public String price() {
        return price;
    }

    public ProductType productType() {
        return productType;
    }

    public List<HouseBaseImage> houseBaseImages() {
        return houseBaseImages;
    }

    public List<BuildingType> buildingTypes() {
        return buildingTypes;
    }

    public String themes() {
        return themes;
    }

    public boolean fineTheme() {
        return fineTheme;
    }

    public void setFineTheme(boolean fineTheme) {
        this.fineTheme = fineTheme;
    }

    public int sort() {
        return sort;
    }

    public void initSort(int sort) {
        this.sort = sort;

    }

    public void addHouseBaseImage(List<HouseBaseImage> findUploadImage) {
      this.houseBaseImages.addAll(findUploadImage);
    }
}
